function [IncAdv_Mat, IncAdvExpChallDem_Weighted_Holder, IncAdvExpChallRep_Weighted_Holder] = getIncAdv_Senate(Theta, VoteDem, VoterIdeal, CandTypeDem, CandTypeRep, DemCandIdeal, DemPartyIdeal, RepCandIdeal, RepPartyIdeal, RHSControls, UtilFuncParam, ChoiceProbForm, Dist_Index)

Lambdas = Theta(1:2,:);
Betas = Theta(3:4,:);
Gamma = Theta(length(Theta),:);

if length(RHSControls(1,:)) >= 1
    RHSCoeff = Theta(5:4+length(RHSControls(1,:)),:);
    SingleIndexVal = CandTypeDem(:,1:2)*Betas(1:2,:) - CandTypeRep(:,1:2)*Betas(1:2,:) + RHSControls*RHSCoeff;
else
    SingleIndexVal = CandTypeDem(:,1:2)*Betas(1:2,:) - CandTypeRep(:,1:2)*Betas(1:2,:);
end


if length(RHSControls(1,:)) >= 1
    RHSCoeff = Theta(5:4+length(RHSControls(1,:)),:);

    SingleIndexValCounterFacIncDem = Betas(1,:) - CandTypeRep(:,1:2)*Betas(1:2,:) + RHSControls*RHSCoeff;
    SingleIndexValCounterFacIncRep = CandTypeDem(:,1:2)*Betas(1:2,:) - Betas(1,:) + RHSControls*RHSCoeff;
    
    SingleIndexValCounterFacExpChallDem = Betas(2,:) - CandTypeRep(:,1:2)*Betas(1:2,:) + RHSControls*RHSCoeff;
    SingleIndexValCounterFacExpChallRep = CandTypeDem(:,1:2)*Betas(1:2,:) - Betas(2,:) + RHSControls*RHSCoeff;
    
    
else
    
    SingleIndexValCounterFacIncDem = Betas(1,:) - CandTypeRep(:,1:2)*Betas(1:2,:);
    SingleIndexValCounterFacIncRep = CandTypeDem(:,1:2)*Betas(1:2,:) - Betas(1,:);

    
    SingleIndexValCounterFacExpChallDem = Betas(2,:) - CandTypeRep(:,1:2)*Betas(1:2,:);
    SingleIndexValCounterFacExpChallRep = CandTypeDem(:,1:2)*Betas(1:2,:) - Betas(2,:);
      
end


EstPosDem=(repmat(DemCandIdeal, 1, 2).*CandTypeDem)*(1-Lambdas) + (repmat(DemPartyIdeal, 1, 2).*CandTypeDem)*(Lambdas);
EstPosRep=(repmat(RepCandIdeal, 1, 2).*CandTypeRep)*(1-Lambdas) + (repmat(RepPartyIdeal, 1, 2).*CandTypeRep)*(Lambdas);
SingleIndexPolicy = -Gamma.*abs(EstPosDem-VoterIdeal).^UtilFuncParam+Gamma.*abs(EstPosRep-VoterIdeal).^UtilFuncParam;

SingleIndex = SingleIndexPolicy + SingleIndexVal;



EstPosDemCounterFacInc = DemCandIdeal*(1-Lambdas(1,:))+DemPartyIdeal*(Lambdas(1,:));
EstPosRepCounterFacInc = RepCandIdeal*(1-Lambdas(1,:))+RepPartyIdeal*(Lambdas(1,:));

EstPosDemCounterFacExpChall = DemCandIdeal*(1-Lambdas(2,:))+DemPartyIdeal*(Lambdas(2,:));
EstPosRepCounterFacExpChall = RepCandIdeal*(1-Lambdas(2,:))+RepPartyIdeal*(Lambdas(2,:));



SingleIndexPolicyCounterFacDemInc = -Gamma.*abs(EstPosDemCounterFacInc-VoterIdeal).^UtilFuncParam+Gamma.*abs(EstPosRep-VoterIdeal).^UtilFuncParam;
SingleIndexPolicyCounterFacRepInc = -Gamma.*abs(EstPosDem-VoterIdeal).^UtilFuncParam+Gamma.*abs(EstPosRepCounterFacInc-VoterIdeal).^UtilFuncParam;

SingleIndexPolicyCounterFacDemExpChall = -Gamma.*abs(EstPosDemCounterFacExpChall-VoterIdeal).^UtilFuncParam+Gamma.*abs(EstPosRep-VoterIdeal).^UtilFuncParam;
SingleIndexPolicyCounterFacRepExpChall = -Gamma.*abs(EstPosDem-VoterIdeal).^UtilFuncParam+Gamma.*abs(EstPosRepCounterFacExpChall-VoterIdeal).^UtilFuncParam;


SingleIndexCounterFacDemInc = SingleIndexPolicyCounterFacDemInc + SingleIndexValCounterFacIncDem;
SingleIndexCounterFacRepInc = SingleIndexPolicyCounterFacRepInc + SingleIndexValCounterFacIncRep;

SingleIndexCounterFacDemExpChall = SingleIndexPolicyCounterFacDemExpChall + SingleIndexValCounterFacExpChallDem;
SingleIndexCounterFacRepExpChall = SingleIndexPolicyCounterFacRepExpChall + SingleIndexValCounterFacExpChallRep;


SingleIndexCounterFacDemInc_NoDir = SingleIndexPolicyCounterFacDemInc + SingleIndexVal;
SingleIndexCounterFacRepInc_NoDir = SingleIndexPolicyCounterFacRepInc + SingleIndexVal;

SingleIndexCounterFacDemExpChall_NoDir = SingleIndexPolicyCounterFacDemExpChall + SingleIndexVal;
SingleIndexCounterFacRepExpChall_NoDir = SingleIndexPolicyCounterFacRepExpChall + SingleIndexVal;


SingleIndexCounterFacDemInc_OnlyVal = SingleIndexPolicy + SingleIndexValCounterFacIncDem;
SingleIndexCounterFacRepInc_OnlyVal = SingleIndexPolicy + SingleIndexValCounterFacIncRep;

SingleIndexCounterFacDemExpChall_OnlyVal = SingleIndexPolicy + SingleIndexValCounterFacExpChallDem;
SingleIndexCounterFacRepExpChall_OnlyVal = SingleIndexPolicy + SingleIndexValCounterFacExpChallRep;

if ChoiceProbForm == 1

    PrVoteLeft = normcdf(SingleIndex, 0, 1);
    
    PrVoteLeftCounterFacDemInc = normcdf(SingleIndexCounterFacDemInc, 0, 1);
    PrVoteLeftCounterFacRepInc = normcdf(SingleIndexCounterFacRepInc, 0, 1);
    
    PrVoteLeftCounterFacDemInc_NoDir = normcdf(SingleIndexCounterFacDemInc_NoDir, 0, 1);
    PrVoteLeftCounterFacRepInc_NoDir = normcdf(SingleIndexCounterFacRepInc_NoDir, 0, 1);
    
    PrVoteLeftCounterFacDemInc_OnlyVal = normcdf(SingleIndexCounterFacDemInc_OnlyVal, 0, 1);
    PrVoteLeftCounterFacRepInc_OnlyVal = normcdf(SingleIndexCounterFacRepInc_OnlyVal, 0, 1);
    
    PrVoteLeftCounterFacDemExpChall = normcdf(SingleIndexCounterFacDemExpChall, 0, 1);
    PrVoteLeftCounterFacRepExpChall = normcdf(SingleIndexCounterFacRepExpChall, 0, 1);
    
    PrVoteLeftCounterFacDemExpChall_NoDir = normcdf(SingleIndexCounterFacDemExpChall_NoDir, 0, 1);
    PrVoteLeftCounterFacRepExpChall_NoDir = normcdf(SingleIndexCounterFacRepExpChall_NoDir, 0, 1);
  
    PrVoteLeftCounterFacDemExpChall_OnlyVal = normcdf(SingleIndexCounterFacDemExpChall_OnlyVal, 0, 1);
    PrVoteLeftCounterFacRepExpChall_OnlyVal = normcdf(SingleIndexCounterFacRepExpChall_OnlyVal, 0, 1);


elseif ChoiceProbForm == 2
    
    PrVoteLeft = exp(SingleIndex)./(1+exp(SingleIndex)); 

    PrVoteLeftCounterFacDemInc = exp(SingleIndexCounterFacDemInc)./(1+exp(SingleIndexCounterFacDemInc));
    PrVoteLeftCounterFacRepInc = exp(SingleIndexCounterFacRepInc)./(1+exp(SingleIndexCounterFacRepInc));
    PrVoteLeftCounterFacDemInc_NoDir = exp(SingleIndexCounterFacDemInc_NoDir)./(1+exp(SingleIndexCounterFacDemInc_NoDir));
    PrVoteLeftCounterFacRepInc_NoDir = exp(SingleIndexCounterFacRepInc_NoDir)./(1+exp(SingleIndexCounterFacRepInc_NoDir)); 
    PrVoteLeftCounterFacDemInc_OnlyVal = exp(SingleIndexCounterFacDemInc_OnlyVal)./(1+exp(SingleIndexCounterFacDemInc_OnlyVal));
    PrVoteLeftCounterFacRepInc_OnlyVal = exp(SingleIndexCounterFacRepInc_OnlyVal)./(1+exp(SingleIndexCounterFacRepInc_OnlyVal)); 

    PrVoteLeftCounterFacDemExpChall = exp(SingleIndexCounterFacDemExpChall)./(1+exp(SingleIndexCounterFacDemExpChall));
    PrVoteLeftCounterFacRepExpChall = exp(SingleIndexCounterFacRepExpChall)./(1+exp(SingleIndexCounterFacRepExpChall));
    PrVoteLeftCounterFacDemExpChall_NoDir = exp(SingleIndexCounterFacDemExpChall_NoDir)./(1+exp(SingleIndexCounterFacDemExpChall_NoDir));
    PrVoteLeftCounterFacRepExpChall_NoDir = exp(SingleIndexCounterFacRepExpChall_NoDir)./(1+exp(SingleIndexCounterFacRepExpChall_NoDir)); 
    PrVoteLeftCounterFacDemExpChall_OnlyVal = exp(SingleIndexCounterFacDemExpChall_OnlyVal)./(1+exp(SingleIndexCounterFacDemExpChall_OnlyVal));
    PrVoteLeftCounterFacRepExpChall_OnlyVal = exp(SingleIndexCounterFacRepExpChall_OnlyVal)./(1+exp(SingleIndexCounterFacRepExpChall_OnlyVal)); 


end


ExpChalltoIncDem_Total = PrVoteLeftCounterFacDemInc(CandTypeDem(:,2)==1,:) - PrVoteLeft(CandTypeDem(:,2)==1,:);
ExpChalltoIncRep_Total = -(PrVoteLeftCounterFacRepInc(CandTypeRep(:,2)==1,:) - PrVoteLeft(CandTypeRep(:,2)==1,:));

ExpChalltoIncDem_Sig = PrVoteLeftCounterFacDemInc_NoDir(CandTypeDem(:,2)==1,:) - PrVoteLeft(CandTypeDem(:,2)==1,:);
ExpChalltoIncRep_Sig = -(PrVoteLeftCounterFacRepInc_NoDir(CandTypeRep(:,2)==1,:) - PrVoteLeft(CandTypeRep(:,2)==1,:));


IncAdvExpChallDem_Total = PrVoteLeft(CandTypeDem(:,1)==1,:)-PrVoteLeftCounterFacDemExpChall(CandTypeDem(:,1)==1,:);
IncAdvExpChallRep_Total = -(PrVoteLeft(CandTypeRep(:,1)==1,:)-PrVoteLeftCounterFacRepExpChall(CandTypeRep(:,1)==1,:));

IncAdvExpChallDem_Sig = PrVoteLeft(CandTypeDem(:,1)==1,:)-PrVoteLeftCounterFacDemExpChall_NoDir(CandTypeDem(:,1)==1,:);
IncAdvExpChallRep_Sig = -(PrVoteLeft(CandTypeRep(:,1)==1,:)-PrVoteLeftCounterFacRepExpChall_NoDir(CandTypeRep(:,1)==1,:));



%Weighting by District

ExpChalltoIncDem_Weighted_Holder = zeros(max(Dist_Index), 1);
ExpChalltoIncRep_Weighted_Holder = zeros(max(Dist_Index), 1);

ExpChalltoIncDem_Sig_Weighted_Holder = zeros(max(Dist_Index), 1);
ExpChalltoIncRep_Sig_Weighted_Holder = zeros(max(Dist_Index), 1);

ExpChalltoIncDem_Val_Weighted_Holder = zeros(max(Dist_Index), 1);
ExpChalltoIncRep_Val_Weighted_Holder = zeros(max(Dist_Index), 1);

IncAdvExpChallDem_Weighted_Holder = zeros(max(Dist_Index), 1);
IncAdvExpChallRep_Weighted_Holder = zeros(max(Dist_Index), 1);

IncAdvExpChallDem_Sig_Weighted_Holder = zeros(max(Dist_Index), 1);
IncAdvExpChallRep_Sig_Weighted_Holder = zeros(max(Dist_Index), 1);

IncAdvExpChallDem_Val_Weighted_Holder = zeros(max(Dist_Index), 1);
IncAdvExpChallRep_Val_Weighted_Holder = zeros(max(Dist_Index), 1);

for d = 1:max(Dist_Index)
    
    ExpChalltoIncDem_Weighted_Holder(d,:) = sum(PrVoteLeftCounterFacDemInc(Dist_Index==d & CandTypeDem(:,2)==1,:) - PrVoteLeft(Dist_Index==d & CandTypeDem(:,2)==1,:))/sum(Dist_Index==d & CandTypeDem(:,2) == 1);
    ExpChalltoIncRep_Weighted_Holder(d,:) =  sum(-(PrVoteLeftCounterFacRepInc(Dist_Index==d & CandTypeRep(:,2)==1,:) - PrVoteLeft(Dist_Index==d & CandTypeRep(:,2)==1,:)))/sum(Dist_Index==d & CandTypeRep(:,2) == 1);

    ExpChalltoIncDem_Sig_Weighted_Holder(d,:) = sum(PrVoteLeftCounterFacDemInc_NoDir(Dist_Index==d & CandTypeDem(:,2)==1,:) - PrVoteLeft(Dist_Index==d & CandTypeDem(:,2)==1,:))/sum(Dist_Index==d & CandTypeDem(:,2) == 1);
    ExpChalltoIncRep_Sig_Weighted_Holder(d,:) = sum(-(PrVoteLeftCounterFacRepInc_NoDir(Dist_Index==d & CandTypeRep(:,2)==1,:) - PrVoteLeft(Dist_Index==d & CandTypeRep(:,2)==1,:)))/sum(Dist_Index==d & CandTypeRep(:,2) == 1);

    ExpChalltoIncDem_Val_Weighted_Holder(d,:) = sum(PrVoteLeftCounterFacDemInc_OnlyVal(Dist_Index==d & CandTypeDem(:,2)==1,:) - PrVoteLeft(Dist_Index==d & CandTypeDem(:,2)==1,:))/sum(Dist_Index==d & CandTypeDem(:,2) == 1);
    ExpChalltoIncRep_Val_Weighted_Holder(d,:) = sum(-(PrVoteLeftCounterFacRepInc_OnlyVal(Dist_Index==d & CandTypeRep(:,2)==1,:) - PrVoteLeft(Dist_Index==d & CandTypeRep(:,2)==1,:)))/sum(Dist_Index==d & CandTypeRep(:,2) == 1);
    
    IncAdvExpChallDem_Weighted_Holder(d,:) = sum(PrVoteLeft(Dist_Index==d & CandTypeDem(:,1) == 1,:)-PrVoteLeftCounterFacDemExpChall(Dist_Index==d & CandTypeDem(:,1) == 1,:))/sum(Dist_Index==d & CandTypeDem(:,1) == 1);
    IncAdvExpChallRep_Weighted_Holder(d,:) = sum(-(PrVoteLeft(Dist_Index==d & CandTypeRep(:,1) == 1,:)-PrVoteLeftCounterFacRepExpChall(Dist_Index==d & CandTypeRep(:,1) == 1,:)))/sum(Dist_Index==d & CandTypeRep(:,1) == 1);

    IncAdvExpChallDem_Sig_Weighted_Holder(d,:) = sum(PrVoteLeft(Dist_Index==d & CandTypeDem(:,1)==1,:)-PrVoteLeftCounterFacDemExpChall_NoDir(Dist_Index==d & CandTypeDem(:,1)==1,:))/sum(Dist_Index==d & CandTypeDem(:,1) == 1);
    IncAdvExpChallRep_Sig_Weighted_Holder(d,:) = sum(-(PrVoteLeft(Dist_Index==d & CandTypeRep(:,1)==1,:)-PrVoteLeftCounterFacRepExpChall_NoDir(Dist_Index==d & CandTypeRep(:,1)==1,:)))/sum(Dist_Index==d & CandTypeRep(:,1) == 1);

    IncAdvExpChallDem_Val_Weighted_Holder(d,:) = sum(PrVoteLeft(Dist_Index==d & CandTypeDem(:,1)==1,:)-PrVoteLeftCounterFacDemExpChall_OnlyVal(Dist_Index==d & CandTypeDem(:,1)==1,:))/sum(Dist_Index==d & CandTypeDem(:,1) == 1);
    IncAdvExpChallRep_Val_Weighted_Holder(d,:) = sum(-(PrVoteLeft(Dist_Index==d & CandTypeRep(:,1)==1,:)-PrVoteLeftCounterFacRepExpChall_OnlyVal(Dist_Index==d & CandTypeRep(:,1)==1,:)))/sum(Dist_Index==d & CandTypeRep(:,1) == 1);

end

ExpChalltoIncDem_Weighted = mean(ExpChalltoIncDem_Weighted_Holder(isnan(ExpChalltoIncDem_Weighted_Holder) == 0));
ExpChalltoIncRep_Weighted = mean(ExpChalltoIncRep_Weighted_Holder(isnan(ExpChalltoIncRep_Weighted_Holder) == 0));

ExpChalltoIncDem_Sig_Weighted = mean(ExpChalltoIncDem_Sig_Weighted_Holder(isnan(ExpChalltoIncDem_Sig_Weighted_Holder) == 0));
ExpChalltoIncRep_Sig_Weighted = mean(ExpChalltoIncRep_Sig_Weighted_Holder(isnan(ExpChalltoIncRep_Sig_Weighted_Holder) == 0));

ExpChalltoIncDem_Val_Weighted = mean(ExpChalltoIncDem_Val_Weighted_Holder(isnan(ExpChalltoIncDem_Val_Weighted_Holder) == 0));
ExpChalltoIncRep_Val_Weighted = mean(ExpChalltoIncRep_Val_Weighted_Holder(isnan(ExpChalltoIncRep_Val_Weighted_Holder) == 0));

IncAdvExpChallDem_Weighted = mean(IncAdvExpChallDem_Weighted_Holder(isnan(IncAdvExpChallDem_Weighted_Holder) == 0));
IncAdvExpChallRep_Weighted = mean(IncAdvExpChallRep_Weighted_Holder(isnan(IncAdvExpChallRep_Weighted_Holder) == 0));

IncAdvExpChallDem_Sig_Weighted = mean(IncAdvExpChallDem_Sig_Weighted_Holder(isnan(IncAdvExpChallDem_Sig_Weighted_Holder) == 0));
IncAdvExpChallRep_Sig_Weighted = mean(IncAdvExpChallRep_Sig_Weighted_Holder(isnan(IncAdvExpChallRep_Sig_Weighted_Holder) == 0));

IncAdvExpChallDem_Val_Weighted = mean(IncAdvExpChallDem_Val_Weighted_Holder(isnan(IncAdvExpChallDem_Val_Weighted_Holder) == 0));
IncAdvExpChallRep_Val_Weighted = mean(IncAdvExpChallRep_Val_Weighted_Holder(isnan(IncAdvExpChallRep_Val_Weighted_Holder) == 0));

SigDecomp_IncAdvExpChallDem = IncAdvExpChallDem_Sig_Weighted/IncAdvExpChallDem_Weighted;
SigDecomp_IncAdvExpChallRep = IncAdvExpChallRep_Sig_Weighted/IncAdvExpChallRep_Weighted;

SigDecomp_ExpChalltoIncDem = ExpChalltoIncDem_Sig_Weighted/ExpChalltoIncDem_Weighted;
SigDecomp_ExpChalltoIncRep = ExpChalltoIncRep_Sig_Weighted/ExpChalltoIncRep_Weighted;

IncAdv_Mat = vertcat(IncAdvExpChallDem_Weighted, IncAdvExpChallRep_Weighted, ExpChalltoIncDem_Weighted, ExpChalltoIncRep_Weighted, SigDecomp_IncAdvExpChallDem, SigDecomp_IncAdvExpChallRep, SigDecomp_ExpChalltoIncDem, SigDecomp_ExpChalltoIncRep, IncAdvExpChallDem_Val_Weighted, IncAdvExpChallRep_Val_Weighted, ExpChalltoIncDem_Val_Weighted, ExpChalltoIncRep_Val_Weighted);